const head = { val: 1, next: null };
const second = { val: 2, next: null };
const third = { val: 3, next: null };

head.next = second;
second.next = third;

let current = head;

while (current) {
  if (current.next === second) {
    current.next = second.next;
    break;
  }

  current = current.next;
}

// 清理被删除节点的引用，避免潜在内存泄漏
second.next = null;

console.log(head);
console.log(second);
console.log(third);
